###################################################
##################R Code for Replicating Figures in "Do Preliminary References Increase Public Support for European Law? Experimental Evidence from Germany"#################
################################################### 

#################
####See Stata Do File for estimation of points used in Figures 1, A3 and A4 ####
#################

#################
#Figure 1
#################
x <- c(1,2,3,4)
y<- c(.539,.67,.619,.54)

par(mgp=c(3,2,0))

plot(x,y,type="n",xlim=c(.9,6.2), ylim=c(0.3,0.65), axes=F,tck=.01, yaxs="i",main="Preliminary References and Support for European Union Law",ylab="Support for EU Law Decision",xlab="")

points(1, .5124, pch=16, col="black")
segments(1,.4906,1,.5341,col="black")
segments(1.05,.5341,.95,.5341,col="black")
segments(1.05,.4906,.95,.4906,col="black")
points(2,.5629, pch=16, col="black")
segments(2,.5411,2,.5848,col="black")
segments(2.05,.5411,1.95,.5411,col="black")
segments(2.05,.5848,1.95,.5848,col="black")
abline(v=2.5)
points(3,.5529, pch=15, col="black")
segments(3,.5283,3,.5776,col="black")
segments(3.05,.5776,2.95,.5776,col="black")
segments(3.05,.5283,2.95,.5283,col="black")
points(3.5,.3914, pch=17, col="gray")
segments(3.5,.3488,3.5,.4341,col="gray")
segments(3.55,.4341,3.45,.4341,col="gray")
segments(3.55,.3488,3.45,.3488,col="gray")
points(5,.5782, pch=15, col="black")
segments(5,.5538,5,.6026,col="black")
segments(4.95,.5538,5.05,.5538,col="black")
segments(4.95,.6026,5.05,.6026,col="black")
points(5.5,.512, pch=17, col="gray")
segments(5.5,.4674,5.5,.5565,col="gray")
segments(5.55,.5565,5.45,.5565,col="gray")
segments(5.55,.4674,5.45,.4674,col="gray")


z<- c(1.8,3.3)
axis(2)
box(bty="L")
mtext("ECJ\nDecision", side=1,at=1.1, line=1,cex=.8)
mtext("German Const.\nCourt Decision", side=1,at=2, line=1,cex=.8)
mtext("ECJ\nDecision", side=1,at=3.25, line=1,cex=.8)
mtext("German Const.\nCourt Decision", side=1,at=5.25, line=1,cex=.8)
mtext("Direct Effects (H1)", side=1,at=1.65, line=-16)
mtext("Conditional Effects (H2)", side=1,at=4.35,line=-16)

legend("bottomleft", inset=c(0, -.3), legend=c("Less or Equal Confidence in German Constitutional Court compared to ECJ","Higher Confidence in German Constitutional Court compared to ECJ"), pch=c(15,17), title="",xpd=T,horiz=F,bty="n",col=c("black","gray"),cex=.8)


#################
#Figures A1 and A2
#################

#Read in dataset: file name is "eu_support.csv"

#Figure A1
barplot(eu_support$more_eu,xlab="Country",names=eu_support$code, ylim=c(0,70),col=c("gray","gray","gray","Black","gray","gray","gray","gray","gray","gray","gray","gray","gray","gray","gray","gray","gray","gray","gray","gray","gray"),main="Support for More EU Integration (2018 ESS)")
box()

#Figure A2
barplot(eu_support$cjeu_trust,xlab="Country",names=eu_support$code, ylim=c(0,80),col=c("gray","gray","gray","gray","Black","gray","gray","gray","gray","gray","gray","gray","gray","gray","gray","gray","gray","gray","gray","gray"),main="Trust in CJEU (2019 Eurobarometer)")
box()

#################
#Figure A3
#################

x <- c(1,2,3,4)
y<- c(.539,.67,.619,.54)

#par(mar=c(3.1,4.1,2.7,2.1))
par(mgp=c(3,2,0))

plot(x,y,type="n",xlim=c(.9,3.2), ylim=c(-0.1,0.15), axes=F,tck=.01, yaxs="i",main="Marginal Effect Plot: Preliminary References, Support for \nEU Integration and Support for European Union Law",ylab="Marginal Effect on Support for EU Law Decision",xlab="")

#segments(1,1.88,2)
points(1, .0712297  , pch=16, col="black")
segments(1,.0251224 ,1,.117337,col="black")
segments(1.05,.0251224 ,.95,.0251224 ,col="black")
segments(1.05,.117337,.95,.117337,col="black")
points(2,.0498964, pch=16, col="black")
segments(2,.0196089,2,.0801839,col="black")
segments(2.05,.0196089,1.95,.0196089,col="black")
segments(2.05,.0801839,1.95,.0801839,col="black")
abline(h=0,lty=2)
points(3,.0285631 , pch=16, col="black")
segments(3,-.0232196,3,.0803458,col="black")
segments(3.05,-.0232196,2.95,-.0232196,col="black")
segments(3.05,.0803458,2.95,.0803458,col="black")


z<- c(1.8,3.3)
axis(2)
box(bty="L")
mtext("EU Unification Has\nGone Too Far", side=1,at=1, line=1,cex=.8)
mtext("EU Unification Has\nGone as Far as It Should ", side=1,at=2, line=1,cex=.8)
mtext("EU Unification\nShould Go Further", side=1,at=3, line=1,cex=.8)
#axis(1, at=z, labels=expression("Germany (H1 and H3)", "Hungary (H2 and H4)"), tck=0, cex.axis=.9,xpd=F)



#################
#Figure A4
#################
x <- c(1,2,3,4)
y<- c(.539,.67,.619,.54)

#par(mar=c(3.1,4.1,2.7,2.1))
par(mgp=c(3,2,0))

plot(x,y,type="n",xlim=c(.9,4.2), ylim=c(-0.05,.2), axes=F,tck=.01, yaxs="i",main="Preliminary References, Relative Trust in Courts\nand Support for Pro-EU Law Decision",ylab="Marginal Effect on Support for EU Law Decision",xlab="")

#segments(1,1.88,2)
points(1, .0146, pch=16, col="black")
segments(1,-0.0239,1,0.053,col="black")
segments(1.05,0.053,.95,0.053,col="black")
segments(1.05,-0.0239,.95,-0.0239,col="black")
points(2,.0791, pch=16, col="black")
segments(2,.0069,2,.1514,col="black")
segments(2.05,.1514,1.95,.1514,col="black")
segments(2.05,.0069,1.95,.0069,col="black")
points(4,.0838, pch=16, col="black")
segments(4,0.0106,4,0.1569,col="black")
segments(4.05,0.1569,3.95,0.1569,col="black")
segments(4.05,0.0106,3.95,0.0106,col="black")
points(3,-0.0037, pch=16, col="black")
segments(3,-0.0426,3,0.0352,col="black")
segments(3.05,0.0352,2.95,0.0352,col="black")
segments(3.05,-0.0426,2.95,-0.0426,col="black")
abline(v=2.5)
abline(h=0,lty=2)


z<- c(1.8,3.3)
axis(2)
box(bty="L")
mtext("German Courts not\nTrusted More than CJEU", side=1,at=1.1, line=1,cex=.8)
mtext("German Courts Trusted\n More than CJEU", side=1,at=2, line=1,cex=.8)
mtext("German Courts not\nTrusted More than CJEU", side=1,at=3.1, line=1,cex=.8)
mtext("German Courts Trusted\n More than CJEU", side=1,at=4.05, line=1,cex=.8)
mtext("Bundesgerichtshof Treatment", side=1,at=1.65, line=-15)
mtext("Finanzgericht Munich Treatment", side=1,at=3.45,line=-15)
#axis(1, at=z, labels=expression("Germany (H1 and H3)", "Hungary (H2 and H4)"), tck=0, cex.axis=.9,xpd=F)
#legend("bottomleft", inset=c(0, -.3), legend=c("Decision Made by National Court and CJEU","Decision Made by CJEU"), pch=c(16,16), title="",xpd=T,horiz=T,bty="n",col=c("gray","black"))

